import React from 'react';
import  FileUpload  from './react-fileupload.js';


class FileUploader extends React.Component{
    render(){
        /*set properties*/
        const options={
            baseUrl:'/manage/product/upload.do',
            // 指定组件的名称
            fileFieldName:'upload_file',
            dataType     :'json',
            // 添加一个属性 当图片已选择 就上传 不需要点击上传
            chooseAndUpload :true,
            // 成功和失败的函数要从外面传
            // 成功和失败 方法都是从这个组件外调用
            uploadSuccess:(res)=>{
                this.props.onSuccess(res.data);
            },
            uploadError  :(err)=>{
                this.props.onError(err.message||'上传图片除错啦');
            }
        }
            
        /*Use FileUpload with options*/
        /*Set two dom with ref*/
        return (
            <FileUpload options={options}>
                <button className="btn btn-xs btn-default" ref="chooseAndUpload">请选择图片</button>
            </FileUpload>
        )	        
    } 
}

export default FileUploader;